package com.zone.vehicle.superApps.utils;

import android.util.Log;

import com.zone.lib.download.db.DownloadDaoUtilsStore;
import com.zone.lib.download.db.entity.Download;
import com.zone.sdk.common.http.base.Result;
import com.zone.sdk.common.http.callback.ResultCallBack;
import com.zone.sdk_api.ApiManager;
import com.zone.vehicle.sdk.module.superapp.entity.SyncStatusEntity;
import com.zone.vehicle.sdk.module.superapp.request.SyncStatusRequest;

import org.apache.commons.lang3.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: pkqlqx
 * @CreateDate: 2021/12/20 21:57
 * @Description:
 */
public class UploadAppStatus {
    private static final String TAG = UploadAppStatus.class.getSimpleName();

    public static void sendAppState(String type, String code, int state, String process, String version){
        SyncStatusEntity entity = new SyncStatusEntity();
        entity.setCode(code);
        entity.setProcess(process);
        entity.setVersion(version);
        entity.setState(state);
        uploadAppStatus(type, entity);
    }

    public static void uploadAppStatus(String type, SyncStatusEntity entity){
        if (ObjectUtils.isEmpty(entity)){
            return;
        }
        Download download = DownloadDaoUtilsStore.getInstance().getDownloadByCode(entity.getCode());
        if (ObjectUtils.isEmpty(download)){
            return;
        }
        SyncStatusRequest request = new SyncStatusRequest();
        request.setType(type);
        List<SyncStatusEntity> statusList = new ArrayList<>();
        statusList.add(entity);
        request.setStatusList(statusList);
        ApiManager.getInstance().syncStatus(request, new ResultCallBack<Result>() {
            @Override
            public void onSuccess(Result result) {
                Log.d(TAG, result.toString());
            }

            @Override
            public void onError(String errorCode, String message) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

}
